import type { DonationType } from '@/types/home'
import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const donationTypeStore = defineStore(
  'donationType',
  () => {
    // 捐赠物种类信息
    const donationTypes = ref<DonationType[]>([])

    // 保存捐赠物种类信息
    const setDonationTypes = (val: DonationType[]) => {
      donationTypes.value = val
    }

    // 清理会员信息，退出时使用
    const clearDonationType = () => {
      donationTypes.value = []
    }

    // 记得 return
    return {
      donationTypes,
      setDonationTypes,
      clearDonationType,
    }
  },
  // TODO: 持久化
  {
    //网页端配置
    //persist: true,
    //小程序端配置
    persist: {
      storage: {
        getItem(key: string) {
          return uni.getStorageSync(key)
        },
        setItem(key: string, value: string) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
